//
//  UIView+aToast.m
//  TzyjMainProj
//
//  Created by DF_ZK on 3/10/17.
//  Copyright © 2017 orientsec. All rights reserved.
//

#import "UIView+aToast.h"

@implementation UIView (aToast)

+ (void)showCustomToast:(NSString *)text
{
    UIView *window = [UIApplication sharedApplication].keyWindow;
    
    NSMutableArray *toastArr = [window get_cs_tostQueue];
    
    for (id obj in toastArr) {
        if ([obj isKindOfClass:[UIView class]]) {
            [obj removeFromSuperview];
        }
    }
    
    [toastArr removeAllObjects];
    
    CGRect screen = [UIScreen mainScreen].bounds;
    
    CGPoint pos = CGPointMake(screen.size.width/2.0, screen.size.height - 100);
    
    [window makeAToast:text duration:1.0 position:[NSValue valueWithCGPoint:pos]];
}

+ (void)showCustomToast:(NSString *)text duration:(NSTimeInterval)duration position:(id)position
{
    UIView *window = [UIApplication sharedApplication].windows.lastObject;
    
    NSMutableArray *toastArr = [window get_cs_tostQueue];
    
    for (id obj in toastArr) {
        if ([obj isKindOfClass:[UIView class]]) {
            [obj removeFromSuperview];
        }
    }
    
    [toastArr removeAllObjects];
    
    [window makeAToast:text duration:duration position:position];
}

- (void)showCustomToast:(NSString *)text
{
    NSMutableArray *toastArr = [self get_cs_tostQueue];
    
    for (id obj in toastArr) {
        if ([obj isKindOfClass:[UIView class]]) {
            [obj removeFromSuperview];
        }
    }
    
    [toastArr removeAllObjects];
    
    CGRect screen = [UIScreen mainScreen].bounds;
    
    CGPoint pos = CGPointMake(screen.size.width/2.0, screen.size.height - 100);
    
    [self makeAToast:text duration:1.0 position:[NSValue valueWithCGPoint:pos]];
}

- (void)showCustomToast:(NSString *)text duration:(NSTimeInterval)duration position:(id)position
{
    NSMutableArray *toastArr = [self get_cs_tostQueue];
    
    for (id obj in toastArr) {
        if ([obj isKindOfClass:[UIView class]]) {
            [obj removeFromSuperview];
        }
    }
    
    [toastArr removeAllObjects];
    
    [self makeAToast:text duration:duration position:position];
}

- (void)showCustomToast:(NSString *)text duration:(NSTimeInterval)duration completion:(void(^)(BOOL didTap))completion
{
    NSMutableArray *toastArr = [self get_cs_tostQueue];
    
    for (id obj in toastArr) {
        if ([obj isKindOfClass:[UIView class]]) {
            [obj removeFromSuperview];
        }
    }
    
    [toastArr removeAllObjects];
    
    [self makeToast:text duration:duration position:CSToastAtPositionBottom title:nil image:nil style:nil completion:completion];
}

- (void)showCustomToast:(NSString *)text duration:(NSTimeInterval)duration position:(id)position title:(NSString *)title image:(UIImage *)image completion:(void(^)(BOOL didTap))completion
{
    NSMutableArray *toastArr = [self get_cs_tostQueue];
    
    for (id obj in toastArr) {
        if ([obj isKindOfClass:[UIView class]]) {
            [obj removeFromSuperview];
        }
    }
    
    [toastArr removeAllObjects];
    
    [self makeToast:text duration:duration position:position title:title image:image style:nil completion:completion];
}

@end
